/*
 * Copyright (c) 2020 hebeiyiliuba.com
 * All rights reserved.
 *
 */
package org.jeecg.modules.third.oapi.alct56.constant.enums;

import com.google.common.collect.Maps;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 货物分类绑定
 *
 * @author duanlikao
 * @created 2021/7/7
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
public enum CargoTypeEnum {
    /**
     * 陆交开放平台 货物分类
     * 10	动物类产品
     * 20	植物产品
     * 30	动植物油及制品
     * 40	烟酒食品饮料
     * 50	矿产品
     * 60	化工品
     * 70	塑料橡胶及制品
     * 80	皮类及制品
     * 90	木制及稻草木制品
     * 100	木浆纤维纸类
     * 110	纺织制品
     * 120	鞋帽伞杖鞭及羽毛制品
     * 130	石料水泥陶瓷玻璃等制品
     * 140	珠宝首饰
     * 150	金属及制品
     * 160	机械电气音响设备及零件
     * 170	车辆船舶航空器及有关运输设备
     * 180	精密仪器及设备
     * 190	武器弹药及零件
     * 200	杂项制品
     * 210	艺术品收藏品及古物
     * 220	特殊交易品及未分类商品
     */
    COAL_PRODUCTS("0100", "煤炭及制品","50"),
    OIL_GAS_PRODUCTS("0200", "石油、天然气及制品","60"),
    METAL_ORE("0300", "金属矿石","50"),
    STEEL("0400", "钢铁","150"),
    MINE_CONSTRUCTION_MATERIALS("0500", "矿建材料","130"),
    CEMENT("0600", "水泥","130"),
    WOOD("0700", "木材","90"),
    NONMETALLIC_ORE("0800", "非金属矿石","50"),
    CHEMICAL_FERTILIZER_PESTICIDE("0900", "化肥及农药","60"),
    SALT("1000", "盐","40"),
    FOODSTUFF("1100", "粮食","20"),
    MACHINERY_EQUIPMENT_ELECTRICAL_APPLIANCES("1200", "机械、设备、电器","160"),
    LIGHT_INDUSTRIAL_RAW_MATERIALS("1300", "轻工原料及制品","120"),
    NONFERROUS_METALS("1400", "有色金属","150"),
    PHARMACEUTICAL_PRODUCTS("1500", "轻工医药产品","60"),
    FRESH_AGRICULTURAL_PRODUCTS("1601", "鲜活农产品","10"),
    REFRIGERATED_GOODS("1602", "冷藏冷冻货物","10"),
    COMMERCIAL_CAR("1702", "商品汽车","170"),
    OTHER("1700", "其他","220"),
    ;

    private  String code;
    private  String msg;

    private  String cargoClass;

    private static Map <String, CargoTypeEnum> codeMap = Maps.newHashMap();


    public String getCode() {
        return this.code;
    }

    public String getDesc() {
        return this.msg;
    }

    public String getCargoClass() {
        return this.cargoClass;
    }

    public static String getMsg(String code) {
        return codeMap.containsKey(code) ? codeMap.get(code).getDesc() : StringUtils.EMPTY;
    }

    public static boolean isValid(String code) {
        return codeMap.containsKey(code);
    }

    static {
        for (CargoTypeEnum status : CargoTypeEnum.values()) {
            codeMap.put(status.getCode(), status);
        }
    }

    public static CargoTypeEnum getCargoTypeEnumByVal(String code) {
        return Arrays.stream(CargoTypeEnum.values()).collect(Collectors.toMap(
                CargoTypeEnum::getCode, value -> value, (k1, k2) -> k2)).get(code);
    }
}
